define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/exchange/index' + location.search,
                    add_url: 'finance/exchange/add',
                    edit_url: 'finance/exchange/edit',
                    del_url: 'finance/exchange/del',
                    multi_url: 'finance/exchange/multi',
                    import_url: 'finance/exchange/import',
                    table: 'exchange',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        // {field: 'play_no', title: __('Play_no'), operate: 'LIKE'},
                        {field: 'zfb_no', title: __('Zfb_no'), operate: 'LIKE'},
                        {field: 'personal.account', title: __('Personal.account'), operate: 'LIKE'},
                        {field: 'personal.nickname', title: __('Personal.nickname'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate: false},
                        {field: 'real_price', title: __('Real_price'), operate: false},
                        {field: 'ip', title: __('Ip'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'oktime', title: __('Oktime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'number', title: __('Number'), operate: false},
                        {field: 'type', title: __('Type'), searchList: {"1":__('微信'),"2":__('支付宝')},  formatter: Table.api.formatter.label},
                        {field: 'come', title: __('Come'), searchList: {"1":__('下单充值'),"2":__('其他')}, operate: false, formatter: Table.api.formatter.label},
                        {field: 'status', title: __("Status"), searchList: {"0":__('未核对'),"1":__('已核对'),"2":__('异常')}, formatter: Table.api.formatter.status},
                        {field: 'content', title: __('Content'), operate: false},
                        {field: 'admin', title: __('操作人'), operate: false},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
